package app.beit.finportal.service.convert;

import java.util.ArrayList;
import java.util.List;

import app.beit.finportal.bean.DocumentsBean;
import app.beit.finportal.entity.Documents;
import app.beit.finportal.utils.StringUtils;

public class DocumentsConvert {

	/**
	 * Convert Entity To Bean
	 * @param entity
	 * @return DocumentsBean
	 */
	public static DocumentsBean entityToBean(final Documents entity){
		final DocumentsBean bean = new DocumentsBean();
		
		bean.setId(entity.getId());
		bean.setCreatedBy(StringUtils.nullToEmpty(entity.getCreatedBy()));
		bean.setCreatedDate(entity.getCreatedDate());
		bean.setDescription(StringUtils.nullToEmpty(entity.getDescription()));
		bean.setFileLocation(StringUtils.nullToEmpty(entity.getFileLocation()));
		bean.setName(StringUtils.nullToEmpty(entity.getName()));
		bean.setStatus(entity.getStatus());
		bean.setUpdatedBy(StringUtils.nullToEmpty(entity.getUpdatedBy()));
		bean.setUpdatedDate(entity.getUpdatedDate());
		bean.setFileName(StringUtils.nullToEmpty(entity.getFileLocation().substring(entity.getFileLocation().lastIndexOf("/")+1)));
		
		return bean;
	}
	
	/**
	 * Convert Bean to Entity
	 * @param bean
	 * @return Documents
	 */
	public static Documents beanToEntity(final DocumentsBean bean){
		final Documents entity = new Documents();
		
		entity.setId(bean.getId());
		entity.setCreatedBy(StringUtils.nullToEmpty(bean.getCreatedBy()));
		entity.setCreatedDate(bean.getCreatedDate());
		entity.setDescription(StringUtils.nullToEmpty(bean.getDescription()));
		entity.setFileLocation(StringUtils.nullToEmpty(bean.getFileLocation()));
		entity.setName(StringUtils.nullToEmpty(bean.getName()));
		entity.setStatus(bean.getStatus());
		entity.setUpdatedBy(StringUtils.nullToEmpty(bean.getUpdatedBy()));
		entity.setUpdatedDate(bean.getUpdatedDate());
		
		return entity;
	}

	/**
	 * Convert List Entity to List Bean
	 * @param entities
	 * @return List DocumentsBean
	 */
	public static List<DocumentsBean> entityToBean(final List<Documents> entities){
		final List<DocumentsBean> beans = new ArrayList<DocumentsBean>();
		
		for(final Documents entity : entities){
			beans.add(DocumentsConvert.entityToBean(entity));
		}
		
		return beans;
	}
	
	/**
	 * Convert List Bean to List Entity
	 * @param beans
	 * @return List Documents
	 */
	public static List<Documents> beanToEntity(final List<DocumentsBean> beans){
		final List<Documents> entities = new ArrayList<Documents>();
		
		for(final DocumentsBean bean : beans){
			entities.add(DocumentsConvert.beanToEntity(bean));
		}
		
		return entities;
	}
	
}
